﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Pages/sales/list_view.master" %>

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        string n = Request.QueryString["h"] ?? "500";
        int h = int.Parse(n) - 100;
        
    }

    protected void page_Init(object sender, EventArgs e)
    {
        this.txt_no.Text = "";//249050
        if (!IsPostBack)
        {
            Session["InvWhere"] = "1=0";
            this.txt_from.Date = DateTime.Today.AddDays(-7);
            this.txt_to.Date = DateTime.Today;
        }
    }

    protected void Search_Click(object sender, EventArgs e)
    {
        string invoiceN = this.txt_no.Text.Trim();
        string where = "";
        if (invoiceN.Length > 0)
        {
            where += string.Format("DocNo='{0}'", invoiceN);
        }
        else
        {
            if (this.txt_from.Value != null && this.txt_to.Value != null)
            {
                where += string.Format("DocDate>='{0}' and DocDate<'{1}'", this.txt_from.Date.ToString("yyyy-MM-dd"), this.txt_to.Date.AddDays(1).ToString("yyyy-MM-dd"));
            }
        }
        if (where.Length > 0)
        {
            where += " and DocType='Invoice'";
            this.dsInvoice.FilterExpression = where;
        }
    }

    #region search
   
    private string GetWhere(string where, string s)
    {
        if (where.Length > 0)
            where += " and " + s;
        else
            where = s;
        return where;
    }
    #endregion

    protected void grid_Order_CustomUnboundColumnData(object sender, ASPxGridViewColumnDataEventArgs e)
    {
        //if (e.Column.FieldName == "CustName")
        //{
        //    Touchmax.JobOrder jo= (sender as ASPxGridView).GetRow(e.ListSourceRowIndex) as Touchmax.JobOrder;
        //    //string sql = "select acctName from Baccount where BaccountID='" + SafeValue.SafeInt(jo.CustCode, 0) + "'";
        //    string sql = "select Name from xxcustomer where oid='" + SafeValue.SafeInt(jo.CustCode, 0) + "'";
        //    e.Value = SafeValue.SafeString(Touchmax.Manager.ORManager.ExecuteScalar(sql), " ");
        //}
    }
    protected void grid_Order_RowCreated(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)
    {
        //    if (e.RowType != DevExpress.Web.ASPxGridView.GridViewRowType.Data) return;
        //    ASPxLabel label = grid_Order.FindRowCellTemplateControl(e.VisibleIndex, null, "lab_InvoiceNo") as ASPxLabel;
        //    if (label == null || label.Text.Length < 3)
        //    {
        //        label.Text = "No Invoice";
        //        if (label != null)
        //        {
        //            label.BackColor = System.Drawing.Color.Green;
        //        }
        //    }
        //    else
        //    {
        //        e.Row.ForeColor = System.Drawing.Color.GreenYellow;
        //    }

    }
    protected void grid_Order_HtmlRowPrepared(object sender, ASPxGridViewTableRowEventArgs e)
    {
        if (e.RowType != DevExpress.Web.ASPxGridView.GridViewRowType.Data) return;
        //ASPxLabel label = grid_Order.FindRowCellTemplateControl(e.VisibleIndex, null, "lab_InvoiceNo") as ASPxLabel;
        //if (label == null || label.Text.Length < 3)
        //{
        //e.Row.ForeColor = System.Drawing.Color.;
        //if (label != null)
        //{
        //    label.Text = "         ";
        //    label.BackColor=System.Drawing.Color.Red;
        //}
        //}
        //else
        //{
        //    //e.Row.Cells[2].BackColor = System.Drawing.Color.LightGreen;

        //            e.Row.BackColor = System.Drawing.Color.LightGreen;
           
    }
    
 
    
</script>


<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style>
    div {font-size:10px;font-family:Verdana;}
    </style>
    <script type="text/javascript">

        function ShowOrder(invN) {
            parent.Popup('/Pages/Sales/EditPage/OrderEdit.aspx?no=' + invN, 'Service Order', 1000, 500);
            // popubCtr.SetHeaderText('Service Order');
            // popubCtr.SetContentUrl('EditPage/OrderEdit.aspx?no=' + invN);
            // popubCtr.Show();
        }
        function ShowInvoice(invN) {
            popubCtr.SetHeaderText('Invoice');
            popubCtr.SetContentUrl('EditPage/InvoiceEdit.aspx?InvN=' + invN);
            popubCtr.Show();
        }
        function PrintBill(invN) {
            parent.window.open("/rpt/printview.aspx?doc=50&no=" + invN);
        }

    </script>
</asp:Content>

<asp:Content ID="title1" ContentPlaceHolderID="Title1" Runat="Server">
<table width=100% cellpadding="4">
    <tr>
    <td align=left class="bb">
        Quick Navigation
    </td>
    <td align=right class="bb">
    </td>
    </tr>
</table>
</asp:Content>
<asp:Content ID="title2" ContentPlaceHolderID="Title2" Runat="Server">

<table width="100%">
           <tr>
                
                <td>
                    Date
                </td>
                <td>
                    <dxe:ASPxDateEdit ID="txt_from" Width="100" runat="server" EditFormat="Custom" EditFormatString="dd/MM/yyyy">
                    </dxe:ASPxDateEdit>
                </td>
                <td>
                    To
                </td>
                <td>
                    <dxe:ASPxDateEdit ID="txt_to" Width="100" runat="server" EditFormat="Custom" EditFormatString="dd/MM/yyyy">
                    </dxe:ASPxDateEdit>
                </td>
                <td>
                    <dxe:ASPxButton ID="ASPxButton1" Width="100" runat="server" Text="Search" OnClick="Search_Click">
                    </dxe:ASPxButton>
                </td>
                <td align=right width="350">
                <dxe:ASPxButton ID="ASPxButton9" Width="100" runat="server" Text="Create New" AutoPostBack="False">
                            <ClientSideEvents Click="function(s, e) {
                    ShowOrder(0);
                        }" />
                        </dxe:ASPxButton>
                </td>
            </tr>
        </table>

</asp:Content>
<asp:Content ID="title3" ContentPlaceHolderID="Title3" Runat="Server">

</asp:Content>

<asp:Content ID="Page1" ContentPlaceHolderID="Page1" Runat="Server">

     
        <table>
  
        <tr>
        <td colspan=2 align=left>
        <asp:RadioButton GroupName="time" Checked="true" ID="RadioButton0" runat="server" Text = "This Month" /><br /> 
        <asp:RadioButton GroupName="time" ID="RadioButton1" runat="server" Text = "Last Month" /><br /> 
        <asp:RadioButton GroupName="time" ID="RadioButton3" runat="server" Text = "Year to Date" /> <br />
        <asp:RadioButton GroupName="time" ID="RadioButton2" runat="server" Text = "" />
<asp:DropDownList id="ddl" 
           runat="server">
         <asp:ListItem>2010-01</asp:ListItem>
         <asp:ListItem>2010-02</asp:ListItem>
         <asp:ListItem>2010-03</asp:ListItem>
         <asp:ListItem>2010-04</asp:ListItem>
         <asp:ListItem>2010-05</asp:ListItem>
         <asp:ListItem>2010-06</asp:ListItem>
         <asp:ListItem>2010-07</asp:ListItem>
         <asp:ListItem>2010-08</asp:ListItem>
         <asp:ListItem>2010-09</asp:ListItem>
      </asp:DropDownList>

<br />
        </td>
        </tr>
        <tr>
        <td colspan=2>
        <hr />
        </td>
        </tr>
        <tr>
        <td colspan=2 align=left>
       <asp:RadioButton  GroupName="status" Checked="True" ID="RadioButton6" runat="server" Text = "All" /><br /> 
        <asp:RadioButton GroupName="status" ID="RadioButton4" runat="server" Text = "Open" /><br /> 
        <asp:RadioButton GroupName="status" ID="RadioButton5" runat="server" Text = "Closed" /><br />
        </td>
        </tr>
        <tr>
        <td colspan=2>
        <hr />
        </td>
        </tr>
        <tr>
        <td width=60>
                    Invoice No
                </td>
                <td>
                    <dxe:ASPxTextBox ID="txt_no" Width="70" runat="server" Text="">
                    </dxe:ASPxTextBox>
                </td>
                </tr>
        </table>

</asp:Content>
<asp:Content ID="Page2" ContentPlaceHolderID="Page2" Runat="Server">

               <wilson:DataSource ID="dsJobOrder" runat="server" ObjectSpace="Touchmax.Manager.ORManager"
            TypeName="Touchmax.OpOrder" KeyMember="Oid" FilterExpression="1=1" />

            <wilson:DataSource ID="dsInvoice" runat="server" ObjectSpace="Touchmax.Manager.ORManager"
            TypeName="Touchmax.OpInvoice" KeyMember="SequenceId" FilterExpression="1=1" />
        <dxwgv:ASPxGridView ID="ASPxGridView1" ClientInstanceName="ASPxGridView1" runat="server" Width="800" DataSourceID="dsInvoice" KeyFieldName="SequenceId"
             AutoGenerateColumns="False">
            <SettingsPager Mode="ShowAllRecords" />
<Settings ShowVerticalScrollBar="false"  />            <Columns>
                <dxwgv:GridViewDataTextColumn Caption="#" VisibleIndex="0" Width="5%">
                    <DataItemTemplate>
                        <a onclick='ShowInvoice(<%# Eval("DocNo") %>);'>
                            Edit</a>
                    </DataItemTemplate>
                </dxwgv:GridViewDataTextColumn>
                
                <dxwgv:GridViewDataTextColumn Caption="Invoice No" FieldName="DocNo" VisibleIndex="1" SortIndex="0" SortOrder="Ascending">
                </dxwgv:GridViewDataTextColumn>
                <dxwgv:GridViewDataDateColumn Caption="Issue Date" FieldName="DocDate" VisibleIndex="2">
                    <PropertiesDateEdit EditFormat="Custom" EditFormatString="dd/MM/yyyy" />
                </dxwgv:GridViewDataDateColumn>
                <dxwgv:GridViewDataTextColumn Caption="Customer" FieldName="CustName" VisibleIndex="4">
                </dxwgv:GridViewDataTextColumn>
                <dxwgv:GridViewDataTextColumn Caption="Term" FieldName="CustName" VisibleIndex="4">
                </dxwgv:GridViewDataTextColumn>
                <dxwgv:GridViewDataTextColumn Caption="Amount" FieldName="TotAmt" VisibleIndex="7">
                <PropertiesTextEdit DisplayFormatString="0.00" />
                </dxwgv:GridViewDataTextColumn>
            </Columns>
            <Settings ShowFooter="True" />
            <TotalSummary>
                <dxwgv:ASPxSummaryItem FieldName="DocNo" ShowInGroupFooterColumn="Count" SummaryType="Count" />
                <dxwgv:ASPxSummaryItem FieldName="TotAmt" ShowInGroupFooterColumn="Amt" SummaryType="Sum" />
            </TotalSummary>
        </dxwgv:ASPxGridView>

        

</asp:Content>
<asp:Content ID="Page3" ContentPlaceHolderID="Page3" Runat="Server">
</asp:Content>

